<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title></title>

	<link rel="stylesheet" href="__PUBLIC__/Bootstrap/Css/bootstrap.min.css" />
	<link rel="stylesheet" href="__PUBLIC__/Css/common.css" />
	<link rel="stylesheet" href="__STATIC__/Uploadify/uploadify.css" />
	<script type="text/javascript" src="__STATIC__/uploadify/jquery-1.8.2.min.js"></script>
	<script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
	<script type="text/javascript" src='__PUBLIC__/Ueditor/ueditor.config.js'></script>
	<script type="text/javascript" src='__PUBLIC__/Ueditor/ueditor.all.min.js'></script>
	<script type="text/javascript" src='__PUBLIC__/Js/goods.js'></script>
	<style type="text/css">
		/*去掉uploadify上传按钮的边框*/
	    .uploadify-button {
	        background-color: transparent;
	        border: none;
	        padding: 0;
	    }
	    .uploadify:hover .uploadify-button {
	        background-color: transparent;
    	}
    	body{
    		margin-bottom: 100px;
    	}
    	#pic-list ul li,#photo-list ul li,.show_list_ul li{
    		width: 80px;
    		margin-right: 10px;
    		float: left;
    		position: relative;
    	}
    	#pic-list ul li a.close,#photo-list ul li a.close,.show_list_ul li a.close{
    		position: absolute;
    		top: 0px;
    		right: 0px;
    		background: #dedede;
    		display: block;
    	}
	</style> 
	<script type="text/javascript">
	$(function(){
		// 删除图片
		$('.close').live('click',function() {
          var li=$(this).parents('li');
          var path=li.attr('path');
           	// 异步删除
          	$.ajax({
                // post方式请求
                type:"post",
                // 请求地址
                url:"{|U:'del_pic'}",
                // 发送到服务器的数据
                data:{path:path},
                success:function(data){
                    li.remove();
                }
          	})
          	              	
   		})

		// 获得旧的类型id
   		var cid = {$oldGood['category_cid']};
   		$('#select_cate').val(cid);
   		// 将原来属性和规格表格里的内容存入到变量中，如果选择的分类是原来的分类就把这个变量中的内容写入到表格中
   		var clone_spec = $('#spec').find('tbody').clone();
   		var clone_attr = $('#attr').find('tbody').clone();

		$('select[name=category_cid]').change(function(){
			// alert($(this).val());
			if($(this).val()==cid){
				$('#spec').html(clone_spec);
				$('#attr').html(clone_attr);
				return;
			}

			//获得选中的option的类型tid
			var tid = $(':selected').attr('tid');
			
			$.ajax({
				type:"post",
				url:"{|U:'getAttrSpec'}",
				data:{tid : tid},
				dataType:'json',
				success:function(phpData){
					//属性
					var attr = '';
					//规格
					var spec = '';
					$.each(phpData, function(k,v) {    
						if(v.class == 0){
						  	attr += '<tr><td>'+v.taname+'</td><td><select name="attr['+v.taid+']"><option value="0">请选择</option>';
						  	$.each(v.tavalue, function(kk,vv) {    
						  		attr += '<option value="'+vv+'">' + vv + '</option>';                                                          
						  	});
						  	attr += '</select></td></tr>';
						}else{
							spec += '<tr><td>'+v.taname+'</td><td><select name="spec['+v.taid+'][tavalue][]"><option value="0">请选择</option>';
						  	$.each(v.tavalue, function(kk,vv) {    
						  		spec += '<option value="'+vv+'">' + vv + '</option>';                                                          
						  	});
						  	spec += '</select></td><td>附加价格<input type="text" name="spec[' + v.taid +'][added][]" value="" /></td><td><span class="add-spec btn btn-success"><i class="icon-plus icon-white"></i>增加规格</span></td></tr>';
						}
					});	
					
					$('#attr').html(attr);
					$('#spec').html(spec);
				}
			});
		})

		
	})
	</script>

</head>
<body>
	<div class="container-fluid">
	<div class="row-fluid">
	<div class="span12">

	<form action="" method='post'>
		<fieldset>
			<legend>编辑商品</legend>
			<table class='table table-bordered table-hover'>
				<thead>
					<tr>
						<th colspan="2" class="btn btn-primary">基本信息</th>
					</tr>
				</thead>
				<tbody>
					<tr class="info">
						<td>所属分类</td>
						<td>
							<select id="select_cate" name="category_cid">
								<option value="0">-请选择-</option>
								<foreach from="$cateData" key="$k" value="$v">
									<option value="{$v.cid}" pid="{$v.pid}" tid="{$v.type_tid}"  <if value="$oldGood['category_cid']==$v['cid']">selected</if>>{$v._name}</option>
								</foreach>
							</select>
						</td>
					</tr>
					<tr class="info">
						<td>所属品牌</td>
						<td>
							<select name="brands_bid">
								<option value="0">-请选择-</option>
								<foreach from="$brandsData" key="$k" value="$v">
									<option value="{$v.bid}" <if value="$oldGood['brands_bid']==$v['bid']">selected</if>>{$v.bname}</option>
								</foreach>
							</select>
						</td>
					</tr>
					<tr class="info">
						<td>商品名称</td>
						<td>
							<input type="text" name='gname' value="{$oldGood.gname}" />
						</td>
					</tr>
					<tr class="info">
						<td>商品描述</td>
						<td>
							<textarea name="msg" cols="100" rows="5">{$oldGood.msg}</textarea>
						</td>
					</tr>
					<tr class="info">
						<td>单位</td>
						<td>
							<input type="text" name='unit' value='{$oldGood.unit}'/>
						</td>
					</tr>
					<tr class="info">
						<td>市价场</td>
						<td>
							<input type="text" name='market_price' value="{$oldGood.market_price}" />
						</td>
					</tr>
					<tr class="info">
						<td>商城价</td>
						<td>
							<input type="text" name='mall_price' value="{$oldGood.mall_price}" />
						</td>
					</tr>
					<tr class="info">
						<td>库存</td>
						<td>
							<input type="text" name='total' value="{$oldGood.total}" />
						</td>
					</tr>
					<tr class="info">
						<td>点击次数</td>
						<td>
							<input type="text" name='click_num' value="{$oldGood.click_num}" />
						</td>
					</tr>
				</tbody>
			</table>

			<p class="btn btn-primary">商品属性</p>
			<table class="table table-bordered table-hover" id='attr' class="info">
				<foreach from="$attr" key="$k" value="$v">
				<if value="$v['class']==0">
				<tr>
					<td>{$v.taname}</td>
					<td>
						<select name="attr[{$v['taid']}]">
							<option value="0">请选择</option>
							<foreach from="$v['tavalue']" key="$kk" value="$vv">
								<option value="{$vv}" <if value="$vv==$v['attr']">selected</if>>{$vv}</option>
							</foreach>
						</select>
					</td>
				</tr>
				</if>
				</foreach>
			</table>
			<p class="btn btn-primary">商品规格</p>
			<table class="table table-bordered table-hover" id='spec'>
				<foreach from="$attr" key="$k" value="$v">
				<if value="$v['class']==1">
				<tr>
					<td>{$v.taname}</td>
					<td>
						<select name="spec[{$v['taid']}][tavalue][]">
							<option value="0">请选择</option>
							<foreach from="$v['tavalue']" key="$kk" value="$vv">
								<option value="{$vv}" <if value="$vv==$v['attr']">selected</if>>{$vv}</option>
							</foreach>
						</select>
					</td>
					<td>附加价格<input type="text" name="spec[{$v['taid']}][added][]" value="{$v['extra_price']}" /></td>
					<td><span class="add-spec btn btn-success"><i class="icon-plus icon-white"></i>增加规格</span></td>
				</tr>
				</if>
				</foreach>
			</table>

			<table class='table table-bordered'>
				<tr>
					<th colspan="3" class="btn btn-primary">列表图</th>
				</tr>
				<tr class="info">
					<td>上传图片</td>
					<input type="hidden" name="figure" value="{$oldGood.figure}"/>
					<td class="hidden_file" style="display:none">
						<input type="file" name='pic' id='pic'  multiple="true"/>
							<span>类型: *.jpg,*.png 大小: 2000KB 数量: 1</span>
							<script type="text/javascript">
						        $(function() {
						            $('#pic').uploadify({
						                'formData'     : {//POST数据
						                    '<?php echo session_name();?>' : '<?php echo session_id();?>',
						                },
						                'fileTypeDesc' : '上传文件',//上传描述
						                'fileTypeExts' : '*.jpg;*.png',
						                'swf'      : '__STATIC__/uploadify/uploadify.swf',
						                'uploader' : '{|U:"upload"}',
						                'buttonText':'选择文件',
						                'fileSizeLimit' : '2000KB',
						                'uploadLimit' : 1000,//上传文件数
						                'width':65,
						                'height':25,
						                'successTimeout':10,//等待服务器响应时间
						                'removeTimeout' : 0.2,//成功显示时间
						                'onUploadSuccess' : function(file, data, response) {
						                    data=$.parseJSON(data);
						                    var imageUrl = data.image?data.url:'__STATIC__/image/default.png';
						                    var li="<li path='"+data.path+"' url='"+data.url+"'><img src='"+imageUrl+"' class='hd-w80 hd-h70' width='80' height='100'/><a class='close' href='javascript:;'>×</a>";
						                    //把地址放到隐藏域
						            		li += '<input type="hidden" name="figure" value="'+data.path+'"/>';
						           			li += '</li>';
						                    $("#pic-list ul").prepend(li);
						                }
						            });
						        });
						    </script>
					</td>
					
					<td class="show_file">
						<if value="$oldGood['figure']">
						<ul class="show_list_ul">
						<li>
		                    <img src="__ROOT__/{$oldGood.figure}" width="100" height="50" alt="" />
		                    <a class="logo-del close" href="javascript:;">×</a>
		                </li>
		                </ul>
		                <else/>
		                    <input type="file" name='pic' id='pic'  multiple="true"/>
							<span>类型: *.jpg,*.png 大小: 2000KB 数量: 1</span>
							<script type="text/javascript">
						        $(function() {
						            $('#pic').uploadify({
						                'formData'     : {//POST数据
						                    '<?php echo session_name();?>' : '<?php echo session_id();?>',
						                },
						                'fileTypeDesc' : '上传文件',//上传描述
						                'fileTypeExts' : '*.jpg;*.png',
						                'swf'      : '__STATIC__/uploadify/uploadify.swf',
						                'uploader' : '{|U:"upload"}',
						                'buttonText':'选择文件',
						                'fileSizeLimit' : '2000KB',
						                'uploadLimit' : 1000,//上传文件数
						                'width':65,
						                'height':25,
						                'successTimeout':10,//等待服务器响应时间
						                'removeTimeout' : 0.2,//成功显示时间
						                'onUploadSuccess' : function(file, data, response) {
						                    data=$.parseJSON(data);
						                    var imageUrl = data.image?data.url:'__STATIC__/image/default.png';
						                    var li="<li path='"+data.path+"' url='"+data.url+"'><img src='"+imageUrl+"' class='hd-w80 hd-h70' width='80' height='100'/><a class='close' href='javascript:;'>×</a>";
						                    //把地址放到隐藏域
						            		li += '<input type="hidden" name="figure" value="'+data.path+'"/>';
						           			li += '</li>';
						                    $("#pic-list ul").prepend(li);
						                }
						            });
						        });
						    </script>
		                </if>

						
					</td>
					<td id='pic-list'>
						<ul></ul>
					</td>
				</tr>
			</table>

			<table class='table table-bordered'>
				<tr>
					<th colspan="3" class="btn btn-primary">商品图册</th>

				</tr>
				<tr class="info">
					<td>上传图片</td>
					
					<td class="show_file1">
						<input type="file" name='photo' id='photo' multiple="true" />
						<span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>
						<script type="text/javascript">
			                $(function() {
			                    $('#photo').uploadify({
			                        'formData'     : {//POST数据
			                            '<?php echo session_name();?>' : '<?php echo session_id();?>',
			                        },
			                        'fileTypeDesc' : '上传文件',//上传描述
			                        'fileTypeExts' : '*.jpg;*.png',
			                        'swf'      : '__STATIC__/uploadify/uploadify.swf',
			                        'uploader' : '{|U:"upload_thumb"}',
			                        'buttonText':'选择文件',
			                        'fileSizeLimit' : '2000KB',
			                        'uploadLimit' : 1000,//上传文件数
			                        'width':65,
			                        'height':25,
			                        'successTimeout':10,//等待服务器响应时间
			                        'removeTimeout' : 0.2,//成功显示时间
			                       'onUploadSuccess' : function(file, data, response) {
		                            data=$.parseJSON(data);
		                            var li = '';
		                            $.each(data, function(k,v) {  
		                            	    li += "<li path='"+v+"' url='"+'__ROOT__/'+v+"'><img src='"+'__ROOT__/'+v+"' class='hd-w80 hd-h70' width='80' height='100'/><span>"+k+"</span><a href='javascript:;' class='close'>×</a>";
		                                	li += '<input type="hidden" name="thumb[]" id="thumb" value="'+v+'" /></li>';                                     
		                            });
		                            $("#photo-list ul").prepend(li);
		                        }
			                    });
								
			                });
			            </script>
					</td>
					<td id='photo-list'>
					
						<ul>
							<if value="$oldDetail['big_pic']">
							<foreach from="$img" key="$k" value="$v">	
								<foreach from="$v" key="$kk" value="$vv">
								<li path="{$vv}" url="__ROOT__/{$vv}">
		                   			<img style="float:left" src="__ROOT__/{$vv}" width="100" height="50" alt="" />
		                   			<input type="hidden" name="thumb[]" value="{$vv}"/>
		                   			<a class="logo-del1 close" href="javascript:;">×</a>
		                   			</li>
		                   		</foreach>
		                    </foreach>
		                </if>
						</ul>
					</td>
				</tr>
			</table>

			<table class='table'>
				<tr class="next_show">
					<th class="btn btn-primary msg">商品信息</th>
				</tr>
				<tr class="hidden info">
					<td>
						<!-- <textarea name="intro" id="intro"></textarea> -->
						<script id="editor" type="text/plain" style="width:900px;height:200px;" name="detail">{$oldDetail.detail}</script>
                    	<script>
                       		var ue = UE.getEditor('editor');
                    	</script>
					</td>
				</tr>
			</table>

			<table class='table'>
				<tr class="next_show">
					<th class="btn btn-primary msg">商品详情</th>
				</tr>
				<tr class="hidden info">
					<td>
						<!-- <textarea name="intro" id="intro"></textarea> -->
						<script id="service_editor" type="text/plain" style="width:900px;height:200px;" name="service">{$oldDetail.service}</script>
                    	<script>
                       		var ue = UE.getEditor('service_editor');
                    	</script>
					</td>
				</tr>
			</table>
			<table class='table'>
				<tr class="next_show">
					<th class="btn btn-primary msg">使用方法</th>
				</tr>
				<tr class="hidden info">
					<td>
						<script id="use_method" type="text/plain" style="width:900px;height:200px;" name="use_method">{$oldDetail.use_method}</script>
                    	<script>
                       		var ue = UE.getEditor('use_method');
                    	</script>
					</td>
				</tr>
			</table>
			<table class='table'>
				<tr class="next_show">
					<th class="btn btn-primary msg">商品实拍</th>
				</tr>
				<tr class="hidden info">
					<td>
						<script id="rel_photo" type="text/plain" style="width:900px;height:200px;" name="rel_photo">{$oldDetail.rel_photo}</script>
                    	<script>
                       		var ue = UE.getEditor('rel_photo');
                    	</script>
					</td>
				</tr>
			</table>
			<!-- <input type="hidden" name='type_tid' value='0'/> -->
			<input id="btn" type="submit" value="确认修改" class="btn btn-primary btn-block btn-large" />
		</fieldset>
	</form>

	</div>
	</div>
	</div>
	
</body>
</html>